1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.webphotos.netbeans.project;
17
18 import java.beans.PropertyChangeListener;
19 import java.io.File;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import javax.swing.Icon;
28 import javax.swing.ImageIcon;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.ProjectInformation;
31 import org.netbeans.spi.project.ActionProvider;
32 import org.netbeans.spi.project.CopyOperationImplementation;
33 import org.netbeans.spi.project.DeleteOperationImplementation;
34 import org.netbeans.spi.project.ProjectState;
35 import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
36 import org.openide.filesystems.FileObject;
37 import org.openide.util.Exceptions;
38 import org.openide.util.ImageUtilities;
39 import org.openide.util.Lookup;
40 import org.openide.util.lookup.Lookups;
41
42
43
44
45
46 public class WebPhotosProject implements Project {
47
48 private final FileObject projectDirectory;
49 private final ProjectState state;
50 private Lookup lkp;
51
52 public WebPhotosProject(FileObject projectDir, ProjectState state) {
53 this.projectDirectory = projectDir;
54 this.state = state;
55 }
56
57 FileObject getFolder(int folder, boolean create) {
58 FileObject result =
59 projectDirectory.getFileObject(WebPhotosProjectFactory.PROJECT_ARCHIVES[folder]).getParent();
60 if (result == null && create) {
61 try {
62 result = projectDirectory.createData(WebPhotosProjectFactory.PROJECT_ARCHIVES[folder]).getParent();
63 } catch (IOException ioe) {
64 Exceptions.printStackTrace(ioe);
65 }
66 }
67 return result;
68 }
69
70 @Override
71 public FileObject getProjectDirectory() {
72 return projectDirectory;
73 }
74
75 @Override
76 public Lookup getLookup() {
77 if (lkp == null) {
78 lkp = Lookups.fixed(new Object[]{
79 state,
80 new ActionProviderImpl(),
81 new WebPhotosDeleteOperation(),
82 new WebPhotosCopyOperation(this),
83 new WebPhotosProjectInformation(),
84 new WebPhotosProjectLogicalView(this),
85 });
86 }
87 return lkp;
88 }
89
90 private final class ActionProviderImpl implements ActionProvider {
91
92 private Map<String, Runnable> supportedOps = new HashMap<String, Runnable>();
93
94
95
96
97 public ActionProviderImpl() {
98 supportedOps.put(ActionProvider.COMMAND_COPY, new Runnable() {
99
100 @Override
101 public void run() {
102 DefaultProjectOperations.performDefaultCopyOperation(WebPhotosProject.this);
103 }
104 });
105 supportedOps.put(ActionProvider.COMMAND_DELETE, new Runnable() {
106
107 @Override
108 public void run() {
109 DefaultProjectOperations.performDefaultDeleteOperation(WebPhotosProject.this);
110 }
111 });
112 }
113
114
115
116 @Override
117 public String[] getSupportedActions() {
118 return supportedOps.keySet().toArray(new String[supportedOps.keySet().size()]);
119 }
120
121 @Override
122 public void invokeAction(String action, Lookup lookup) throws IllegalArgumentException {
123 supportedOps.get(action).run();
124 }
125
126 @Override
127 public boolean isActionEnabled(String command, Lookup lookup) throws IllegalArgumentException {
128 if (Arrays.binarySearch(getSupportedActions(), command) >= 0) {
129 return true;
130 } else {
131 throw new IllegalArgumentException(command);
132 }
133 }
134 }
135
136 private final class WebPhotosDeleteOperation implements DeleteOperationImplementation {
137
138 @Override
139 public void notifyDeleting() throws IOException {
140 }
141
142 @Override
143 public void notifyDeleted() throws IOException {
144 }
145
146 @Override
147 public List<FileObject> getMetadataFiles() {
148 List<FileObject> dataFiles = new ArrayList<FileObject>();
149 return dataFiles;
150 }
151
152 @Override
153 public List<FileObject> getDataFiles() {
154 List<FileObject> dataFiles = new ArrayList<FileObject>();
155 return dataFiles;
156 }
157 }
158
159 private class WebPhotosCopyOperation implements CopyOperationImplementation {
160
161 private final WebPhotosProject project;
162 private final FileObject projectDir;
163
164 public WebPhotosCopyOperation(WebPhotosProject project) {
165 this.project = project;
166 this.projectDir = project.getProjectDirectory();
167 }
168
169 @Override
170 public void notifyCopying() throws IOException {
171 }
172
173 @Override
174 public void notifyCopied(Project arg0, File arg1, String arg2) throws IOException {
175 }
176
177 @Override
178 public List<FileObject> getMetadataFiles() {
179 return Collections.EMPTY_LIST;
180 }
181
182 @Override
183 public List<FileObject> getDataFiles() {
184 return Collections.EMPTY_LIST;
185 }
186 }
187
188 private final class WebPhotosProjectInformation implements ProjectInformation {
189
190 @Override
191 public String getName() {
192 return getProjectDirectory().getName();
193 }
194
195 @Override
196 public String getDisplayName() {
197 return getName();
198 }
199
200 @Override
201 public Icon getIcon() {
202 return new ImageIcon(ImageUtilities.loadImage(
203 Constants.PROJECT_ICON));
204 }
205
206 @Override
207 public Project getProject() {
208 return WebPhotosProject.this;
209 }
210
211 @Override
212 public void addPropertyChangeListener(PropertyChangeListener arg0) {
213
214 assert arg0 != null : arg0;
215 }
216
217 @Override
218 public void removePropertyChangeListener(PropertyChangeListener arg0) {
219
220 assert arg0 != null : arg0;
221 }
222 }
223 }